package com.crrc.dataparse.monitor.rsp.service.parse.treat.templatepara.datatrans;

import com.crrc.dataparse.templatepara.IDataTrans;
import java.text.DecimalFormat;

/*
    2进制转Double低端在前
 */
public class HexToDouble2 extends IDataTrans {
    @Override
    public String trans(String value, double resolution, double offset) throws Exception {
        if (value.length() % 8 == 0) {
            StringBuffer sb = new StringBuffer();
            for (int i = value.length()-1; i >= 0; i -= 8) {
                int j = 7;
                while (j >= 0) {
                    sb.append(value.charAt(i - j));
                    j--;
                }
            }
            value = sb.toString();
        }
        long hex = Long.valueOf(value, 2);
        double d = Double.longBitsToDouble(hex);
        //String format = String.valueOf(resolution);
        //format = format.substring(0, format.length() - 1) + "0";
        String format = "0.000000";
        DecimalFormat df = new DecimalFormat(format);

        String result = df.format(d);
        return result;
    }

}